package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Collections;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/main").setViewName("main");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/doctor").setViewName("doctor");
        registry.addViewController("/schedule").setViewName("schedule");
        registry.addViewController("/appointment").setViewName("appointment");
        registry.addViewController("/waiting").setViewName("waiting");

        registry.addViewController("/adminLogin").setViewName("adminLogin");
        registry.addViewController("/adminMain").setViewName("adminMain");
        registry.addViewController("/departmentList").setViewName("departmentList");
        registry.addViewController("/addDepartment").setViewName("addDepartment");
        registry.addViewController("/updateDepartment").setViewName("updateDepartment");
        registry.addViewController("/doctorList").setViewName("doctorList");
        registry.addViewController("/addDoctor").setViewName("addDoctor");
        registry.addViewController("/updateDoctor").setViewName("updateDoctor");
        registry.addViewController("/deleteDoctor").setViewName("deleteDoctor");
        registry.addViewController("/scheduleList").setViewName("scheduleList");
        registry.addViewController("/addSchedule").setViewName("addSchedule");
        registry.addViewController("/updateSchedule").setViewName("updateSchedule");
        registry.addViewController("/waitingList").setViewName("waitingList");

    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // 添加表单数据转换器
        FormHttpMessageConverter formConverter = new FormHttpMessageConverter();
        formConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_FORM_URLENCODED));
        converters.add(formConverter);

        // 添加JSON数据转换器
        MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
        converters.add(jsonConverter);

        // 注意：如果调用了super.configureMessageConverters，会导致Spring Boot的自动配置失效
        // 这里不调用super方法，而是手动配置所有需要的转换器
    }
}